<?php
/**
 * SQLParty主题 header
 * 包括整个<head>和内容部分的上层导航。
 *
 * @package WordPress
 * @subpackage SQLParty
 * @since 2013-06-29
 */
define("UNKNOWN_POST","文章未找到");
define("DAILY_START","20130723");
define("SQLPARTY_ID",14);
define("SQLPARTY_TITLE","SQLParty");
?>
<!DOCTYPE html>
<html lang="cn">
  <head>
    <script type="text/javascript">
        var _speedMark = new Date();
    </script>
    <meta charset="utf-8">
    <title>
    <?php
        //情况1.首页  "SQLParty | 精解SQL方言(MySQL/Oracle/SQLServer/DB2)，精选IT文章"
        //情况2.SQL汇 "文章Category | SQLParty"
        //情况3.每日一题/SQL周边/关于 "文章标题 | SQLParty"
        //判断page_type,当前有4中：首页home，SQL汇sqldialect，每日一题daily，SQL周边around，关于about
        if(is_home())  //首页
        {
            echo "SQLParty | 精解SQL方言(MySQL/Oracle/SQLServer/DB2)，精选IT文章";
        }
        elseif(is_tag())  //SQL周边 标签页
        {
            $page_type=single_tag_title( '', false );
            echo $page_type." 标签 | ".SQLPARTY_TITLE;
            if($page_type == "数据库")
            {
                $page_type = "database";
            }
            elseif($page_type == "系统")
            {
                $page_type = "system";
            }
            else
            {
                $page_type="morenav";
            }
        }
        elseif(is_search())   //搜索页
        {
            $page_type="search";
            echo "搜索 ".get_search_query()." | ".SQLPARTY_TITLE;
        }
        elseif(is_archive())
        {
            $page_type="archive";
            echo "归档文章 ".get_the_date( 'F Y' )." | ".SQLPARTY_TITLE;
        }
        elseif(is_404())
        {
            echo UNKNOWN_POST." 404 | ".SQLPARTY_TITLE;
        }        
        else
        {
            $page_type=str_replace('.php','',basename( get_page_template() ));
            $page_type=trim($page_type);
            if($page_type == "daily")  //每日一题
            {
                if(isset($_GET["d"])) //格式yyyymmdd 8位
                {
                    $yyyymmdd=$_GET["d"];
                    if(strlen($yyyymmdd)==8)
                    {
                        $args = array(
                            'category_name'  => 'daily',
                            'posts_per_page'  => 1,
                            'offset'          => 0,
                            'orderby'         => 'post_date',
                            'order'           => 'DESC',
                            'year'            => substr($_GET["d"],0,4),
                            'monthnum'        => substr($_GET["d"],4,2),
                            'day'             => substr($_GET["d"],6,2)
                            );
                    }
                    elseif(strlen($yyyymmdd)==6)
                    {
                        $args = array(
                            'category_name'  => 'daily',
                            'posts_per_page'  => 1,
                            'offset'          => 0,
                            'orderby'         => 'post_date',
                            'order'           => 'DESC',
                            'year'            => substr($_GET["d"],0,4),
                            'monthnum'        => substr($_GET["d"],4,2)
                            );
                    }
                    else
                    {
                        $args = array(
                            'category_name'  => 'daily',
                            'posts_per_page'  => 1,
                            'offset'          => 0,
                            'orderby'         => 'post_date',
                            'order'           => 'DESC'
                            );
                    }
                }
                else
                {
                    $args = array(
                        'category_name'  => 'daily',
                        'posts_per_page'  => 1,
                        'offset'          => 0,
                        'orderby'         => 'post_date',
                        'order'           => 'DESC'
                        );
                }
                $query = new WP_Query( $args );

                //The Loop
                if ( $query->have_posts() ) 
                {
                    $query->the_post();
                    $title=get_the_title();
                } else {
                    $title=UNKNOWN_POST;
                    define("DAILY_NOPOST","Y");
                }
                echo $title. " | ".SQLPARTY_TITLE;
            }
            elseif($page_type == "morenav")
            {
                echo "最新文章 | ".SQLPARTY_TITLE;
            }
            elseif($page_type == "about")  //关于
            {
                echo "关于 | SQLParty 精解SQL方言(MySQL/Oracle/SQLServer/DB2)，精选IT文章";
            }
            elseif($page_type == "page" and is_page())  //SQL汇
            {            
                $page_type="sqlparty";
                echo get_the_title() . " | ".SQLPARTY_TITLE;
            }
            elseif(is_singular())  //单篇文章
            {
                $page_type="single";
                if(have_posts())
                {
                    the_post();
                    echo get_the_title()." | ".SQLPARTY_TITLE;
                }
                else
                {
                    echo UNKNOWN_POST." | ".SQLPARTY_TITLE;
                }                
            }
            else
            {
                UNKNOWN_POST." | ".SQLPARTY_TITLE;
            }
        }        
    ?>
    </title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="SQLParty | 精解SQL方言(MySQL/Oracle/SQLServer/DB2)，精选IT文章">
    <meta name="author" content="ShiCarl">

    <!-- Le styles -->
    <link href="/wp-content/themes/party/css/bootstrap.min.css" rel="stylesheet">
    <link href="/wp-content/themes/party/css/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="/wp-content/themes/party/css/datetimepicker.css" rel="stylesheet">
    <link href="/wp-content/themes/party/style.css" rel="stylesheet">
    <link href="/wp-content/themes/party/img/logo.png" rel="shortcut icon">
    
    <?php 
        if(is_home() || $page_type == "daily")
        {
    ?>
            <style>
            .dailyanswer {
                display:none;
            }
            </style>
    <?php
        }
    ?>
    
    <script src="/wp-content/themes/party/js/jquery-1.10.2.min.js"></script>
    

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="/wp-content/themes/party/js/html5.js"></script>
    <![endif]-->
    <style type="text/css">
    #scrollUp {
      bottom: 20px;
      right: 20px;
      height: 38px;  /* Height of image */
      width: 38px; /* Width of image */
      background: url("/wp-content/themes/party/img/top.png") no-repeat;
    }
    </style>
    
    
    <?php
	/* Always have wp_head() just before the closing </head>
	 * tag of your theme, or you will break many plugins, which
	 * generally use this hook to add elements to <head> such
	 * as styles, scripts, and meta tags.
	 */
	wp_head();
    ?>
  </head>

  <body>
    <div class="navbar navbar-inverse">
      <div class="navbar-inner">
        <div class="container">
          <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="brand" href="/">SQLParty</a>
          <div class="nav-collapse collapse">
            <ul class="nav">
              <li class="divider-vertical"></li>
              <li <?php if(is_home()) echo 'class="active"' ?>><a href="/">首页</a></li>
              <li class="dropdown <?php if($page_type == "sqlparty") echo ' active' ?>">
                <a href="/sqlparty/" class="dropdown-toggle" data-toggle="dropdown">SQL汇 <b class="caret"></b></a>
                <ul class="dropdown-menu">
                  <?php
                  $args = array(
                        'depth'        => 1,
                        'child_of'     => SQLPARTY_ID,
                        'title_li'     => ''
                    ); 
                    wp_list_pages($args);
                  ?>
                </ul>
              </li>
              <li <?php if($page_type == "daily") echo 'class="active"' ?>><a href="/daily/">每日一题</a></li>
              <li class="divider-vertical"></li>
              <li <?php if($page_type == "database") echo 'class="active"' ?>><a href="/tag/database/">数据库</a></li>
              <li <?php if($page_type == "system") echo 'class="active"' ?>><a href="/tag/system/">系统</a></li>
              <li  <?php if($page_type == "morenav") echo 'class="active"' ?>><a href="/morenav/">...</a></li>
              <li class="divider-vertical"></li>
              <li <?php if($page_type == "about") echo 'class="active"' ?>><a href="/about/">关于</a></li>
            </ul>
            <form id="searchform" action="/" method="get" role="search" class="navbar-search pull-right">
                <input id="s" name="s" type="text" class="search-query" placeholder="搜索">
            </form>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>
